#ifndef KEFONG_CEF_HANDLER_H_
#define KEFONG_CEF_HANDLER_H_
#pragma once

#include "include/cef_client.h"
#include <list>

namespace t3exapp {
	class CCefHandler:public CefClient,
		public CefDisplayHandler,
		public CefLifeSpanHandler,
		public CefLoadHandler
	{
	public:
		CCefHandler();
		~CCefHandler();

		static CCefHandler* GetInstance();

		// CefClient methods:
		virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {
			return this;
		}
		virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override {
			return this;
		}
		virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override { return this; }

		// CefDisplayHandler methods:
		virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
			const CefString& title) override;

		// CefLifeSpanHandler methods:
		virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
		virtual bool DoClose(CefRefPtr<CefBrowser> browser) override;
		virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;

		CefRefPtr<CefBrowser> GetBrowser();


		void CloseAllBrowsers(bool force_close);
		bool IsClosing() const { return is_closing_; }

	private:
		typedef std::list<CefRefPtr<CefBrowser>> BrowserList;
		BrowserList browser_list_;		
		bool is_closing_;

		CefRefPtr<CefBrowser> m_browser;

		// Include the default reference counting implementation.
		IMPLEMENT_REFCOUNTING(CCefHandler);

	};
}

#endif  // KEFONG_CEF_HANDLER_H_
